﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Restaurant.BUS;
using Restaurant.DTO;

namespace Restaurant.User_Control
{
    public partial class ThongKeNH : UserControl
    {
        private NhaHangService nhService = new NhaHangService();
        public bool fix = false;
        public bool unrepeat = false;
        public bool phantom = false;
        int soluong = 0;

        public ThongKeNH()
        {
            InitializeComponent();
        }

        private void HienThiThongTin(DataTable dbtab)
        {
            lv_NH.Items.Clear();
            lbSoLuong.Text = soluong.ToString();
            for (int i = 0; i < dbtab.Rows.Count; i++)
            {
                DataRow dbrow = dbtab.Rows[i];
                ListViewItem liv = new ListViewItem();
                liv.Text = dbrow[0].ToString();
                liv.SubItems.Add(dbrow[1].ToString());
                liv.SubItems.Add(dbrow[2].ToString());
                liv.SubItems.Add(dbrow[3].ToString());
                lv_NH.Items.Add(liv);
            }
        }

        private void LoadNH()
        {
            DataTable dbtab = new DataTable();
            if (unrepeat && !fix)
            {
                dbtab = nhService.LoadNHUnrepeatError(ref soluong);
                HienThiThongTin(dbtab);
                return;
            }
            if (unrepeat && fix)
            {
                dbtab = nhService.LoadNHUnrepeat(ref soluong);
                HienThiThongTin(dbtab);
                return;
            }
            if (phantom && !fix)
            {
                dbtab = nhService.LoadNHPhantomError(ref soluong);
                HienThiThongTin(dbtab);
                return;
            }
            if (phantom && fix)
            {
                dbtab = nhService.LoadNHPhantom(ref soluong);
                HienThiThongTin(dbtab);
                return;
            }
            dbtab = nhService.LoadNH();
            HienThiThongTin(dbtab);
        }

        private void btnQuanLy_Click(object sender, EventArgs e)
        {
            frmQLNhaHang frm = new frmQLNhaHang();
            frm.ShowDialog();
        }

        private void ThongKeNH_Load(object sender, EventArgs e)
        {
            LoadNH();
        }
    }
}
